# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=usbredir
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.13.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
pkgdesc="Parser for the usbredir protocol (mingw-w64)"
depends=(
  "${MINGW_PACKAGE_PREFIX}-libusb"
  "${MINGW_PACKAGE_PREFIX}-glib2"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-meson"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
)
options=('strip' 'staticlibs')
license=("spdx:GPL-2.0-or-later AND LGPL-2.1-or-later")
url="https://www.spice-space.org/"
source=(https://www.spice-space.org/download/usbredir/${_realname}-${pkgver}.tar.xz
        "0001-fix-callback-call-conv.patch")
sha256sums=('4ba6faa02c0ae6deeb4c53883d66ab54b3a5899bead42ce4ded9568b9a7dc46e'
            '27365d5ca6a1c85bed705a1ea0785082f036f99d7f3a11d9e13317da8f89d163')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  # fails to build for 32bit otherwise because it's expecting __stdcall
  patch -p1 -i "${srcdir}/0001-fix-callback-call-conv.patch"
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      ../${_realname}-${pkgver}

  meson compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" meson install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB"
}
